//
//  HomeTopView.m
//  YiXiProject
//
//  Created by iMac on 2019/7/18.
//  Copyright © 2019 iMac. All rights reserved.
//

#import "HomeTopView.h"

@implementation HomeTopView

-(UIButton *)leftBtn
{
    if(!_leftBtn)
    {
        _leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _leftBtn.tag = 100;
        [_leftBtn setImage:[UIImage imageNamed:@"navLeftImg"] forState:UIControlStateNormal];
        [_leftBtn addTarget:self action:@selector(clickBtn:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _leftBtn;
}

-(UIImageView *)fireImg
{
    if(!_fireImg)
    {
        _fireImg = [[UIImageView alloc] init];
        _fireImg.image = [UIImage imageNamed:@"navTitleImg"];
    }
    return _fireImg;
}


-(UIButton *)rightbtn
{
    if(!_rightbtn)
    {
        _rightbtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _rightbtn.tag = 101;
        [_rightbtn setImage:[UIImage imageNamed:@"navRightImg"] forState:UIControlStateNormal];
        [_rightbtn addTarget:self action:@selector(clickBtn:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _rightbtn;
}


-(instancetype)initWithFrame:(CGRect)frame
{
    if(self = [super initWithFrame:frame])
    {
        [self addSubview:self.leftBtn];
        [self addSubview:self.fireImg];
        [self addSubview:self.rightbtn];
    }
    return self;
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    
    _leftBtn.sd_layout.leftSpaceToView(self, 20).bottomSpaceToView(self, 15).widthIs(40).heightIs(40);
    _fireImg.sd_layout.leftSpaceToView(self, SCREEN_WIDTH/2-20).bottomSpaceToView(self, 15).widthIs(40).heightIs(48);
    _rightbtn.sd_layout.rightSpaceToView(self, 20).bottomSpaceToView(self, 15).widthIs(40).heightIs(40);
}

-(void)clickBtn:(UIButton *)btn
{
    if([_delegate respondsToSelector:@selector(clickBtnTag:)])
    {
        [_delegate clickBtnTag:btn.tag];
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
